package com.niiwoo.civet.trade.report.ifcert.niwo;

import com.niiwoo.civet.trade.property.IfcertProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
@EnableConfigurationProperties(IfcertProperties.class)
public class ReprotDataService {
    @Autowired
    private IfcertProperties ifcertProperties;

    @Autowired
    private List<ReporterAdapter> reporterAdapters;

    public void report(List<Long> projectIds, List<ReportEvents> reportEvents){
        reporterAdapters.forEach( report ->{
            if (report.support(reportEvents)){
                try {
                    report.doReport(projectIds,ifcertProperties);
                }catch (Exception e){
                    log.error("上报异常,事件{}",report.supportEvents.name(),e);
                }
            }
        });
    }
}
